<?php
if($_POST['act'] == 'saveTagName'){
    if($_POST['tagid']>0){
        $sql = "update ".SNSPICTAGS." set tagname='".$_POST['tagname']."' where id=".$_POST['tagid'];
        $db->query($sql);
        echo 'ok';exit;
    }
}
if($_GET['act']=='op'){
    if(!empty($_GET['chk'])){
        $tagids = "";
        foreach ($_GET['chk'] as $tagid)
        {
            $tagids .= $tagid.",";
        }
        if($tagids!=""){
            if($_GET['set_status']!=""){
                $sql = "update ".SNSPICTAGS." set status='".$_GET['set_status']."' where id IN (".rtrim($tagids,",").")";
                $db->query($sql);
            }
            if($_GET['changeTagName']!=""){
                $sql = "update ".SNSPICTAGS." set tagname='".$_GET['changeTagName']."' where id IN (".rtrim($tagids,",").")";
                $db->query($sql);
            }
        }
    }
}
if($_GET['act']=='changeTagName'){
    
}else{
    $where = "";
    $timeorder = "desc";
    if($_GET['sdate']!='' && $_GET['edate']!='' && (strtotime($_GET['sdate'])<=strtotime($_GET['edate']))){
        $where .=" and a.create_time>='".$_GET['sdate']."' and a.create_time<='".$_GET['edate']."'";
    }else{
        if($_GET['sdate']!='' && $_GET['edate']==''){
            $where .=" and a.create_time>='".$_GET['sdate']."'";
        }
        if($_GET['sdate']=='' && $_GET['edate']!=''){
            $where .=" and a.create_time<='".$_GET['edate']."'";
        }
    }
    if($_GET['username']!=''){
        $where .=" and b.username like '%$_GET[username]%'";
    }
    if($_GET['tagname']!=''){
        $where .=" and c.tagname like '%".mysql_escape_string($_GET[tagname])."%'";
    }
    if($_GET['brandid'] && $_GET['brand']){
        $where .=" and c.brandid='".$_GET['brandid']."'";
    }elseif ($_GET['brand']!=''){
    	$where .=" and c.brand LIKE '%".mysql_escape_string($_GET['brand'])."%'";
    }
    if($_GET['status']!=""){
        $where .=" and a.status='$_GET[status]'";
    }
    if($_GET['timeorder']=='asc'){
        $timeorder = "asc";
    }

    $sql = "select a.*,b.username,c.tagname as tag_name from ".SNSPICTAGS." a left join ".MEMBER." b on a.member_id=b.userid left join ".SNSTAGS." c on a.tag_id=c.id where 1".$where." order by create_time ".$timeorder;
    $db->query($sql);
    include_once("../includes/page_utf_class.php");
    $page = new Page;
    $page->listRows=20;
    $db->query($sql);
    $totalRows = $db->num_rows();
    if (!$page->__get('totalRows')){
        $db->query($sql);
        $page->totalRows = $db->num_rows();
    }
    $sql .= "  limit ".$page->firstRow.",".$page->listRows;
    
    $db->query($sql);
    $de['page'] = $page->prompt();
    $de['list']=$db->getRows();
}

$tpl->assign('countpro',$totalRows);
$tpl->assign('de',$de);
$tpl->display('sns_pic_tags.htm');
?>